package com.douban.crawl.db;

import com.douban.crawl.model.Movie;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MovieDao {

    private BaseDao baseDao = new BaseDao();

    public void save(Movie movie) {
        baseDao.insert(movie);
    }

    public void update(Movie movie) {
        baseDao.update(movie);
    }

    public List<Movie> getList() {
        return baseDao.getList(Movie.class);
    }

    public List<Movie> getList(Integer limitSize) {
        return baseDao.getList(Movie.class, limitSize);
    }

    public Movie getOne(String movieId) {
        Map<String, String> queryMap = new HashMap<>();
        queryMap.put("dbid", movieId);
        ArrayList<Movie> list = baseDao.getList(Movie.class, queryMap);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
